<template>
    <div>
      <h1>病房添加</h1>
      <table>
        <tbody>
          <tr>
            <td>病房编号：</td>
            <td><input type="text" v-model="info.card"></td>
          </tr>
          <tr>
            <td>病房姓名：</td>
            <td><input type="text" v-model="info.name"></td>
          </tr>
          <tr>
            <td>所属科室</td>
            <td>
            <select v-model="info.keshiid">
              <option value="">请选择</option>
              <option :value="item.id" v-for="item in data.list">
                {{ item.name   }}
              </option>
            </select>
          </td>
          </tr>
          <tr>
            <td>床位总数量</td>
            <td><input type="text" v-model="info.num"></td>
          </tr>
          <tr>
            <td>状态</td>
            <td>
              <input type="radio" v-model="info.stare" value="false">启用
              <input type="radio" v-model="info.stare" value="true">维修
            </td>
          </tr>
          <tr>
            <td>剩余床位</td>
            <td><input type="text" v-model="info.shengyuNum"></td>
          </tr>
          <tr>
            <td></td>
            <td>
              <button @click="add">确认</button>
            </td>
          </tr>
        
          </tbody>
      </table>
    </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue';
import axios from 'axios';
import moment from 'moment';
import { useRouter, useRoute } from 'vue-router';
//修改get
const router = useRouter();
const route = useRoute();
let info:any=reactive({
    card: "",
  name: "",
  keshiid: "",
  num: "",
  stare: false,
  shengyuNum: "",
  
 
})
let data:any=reactive({
  list: [],
})
onMounted(()=>{
yisheng(); 
})

const add=()=>{
 if(info.name==''){
   alert('病房名不能为空')
   return; 
 }
 if(info.keshiid==''){
   alert('请选择科室')
   return; 
 }
 if(info.num==''){
   alert('请输入床位总数量') 
   return;
 }
 axios({
   url:'/api/yisheng/Addbingfang',
   method:'post',
   data :info
 }) 
.then(res=>{
    if(res.data==-1){
      alert('编号不能重复')
      return;
    }
   if(res.data==1){
      alert('添加成功')
      router.push('/Showbingfang');
   }
   else{
     alert('添加失败')
     return; 
   }
 }) 

}
const yisheng=()=>{
 axios({
   url:'/api/yisheng/showkeshi',
   method:'get',
   data:info
 }) 
.then(res=>{
   data.list=res.data;
   console.log(data.list);})
   .catch(err=>{
    console.log(err);
  })
}


</script>

<style scoped>

</style>